/* jshint esversion: 6 */
import VueRouter from 'vue-router';
import homeContainer from './components/tabBar/homeContainer.vue';
import messageContainer from './components/tabBar/messageContainer.vue';
import cartContainer from './components/tabBar/cartContainer.vue';
import memberContainer from './components/tabBar/memberContainer.vue';

import shopping from './components/home/shop/shopping.vue';
import newsList from './components/home/news/newsList.vue';
import galleryList from './components/home/gallery/galleryList.vue';
import introduce from './components/home/intro/introduce.vue';
import history from './components/home/history/history.vue';
import poetry from './components/home/poetry/poetry.vue';

import newsDetail from './components/home/news/newsDetail.vue';
import galleryDetail from './components/home/gallery/galleryDetail.vue';

import goodsList from './components/home/shop/goodsList.vue';
import itemDetail from './components/home/shop/itemDetail.vue';
import storeDetail from './components/home/shop/storeDetail.vue';

import register from './components/subcomponents/register.vue';
import login from './components/subcomponents/login.vue';

import addressList from './components/member/addressList.vue';
import addAddress from './components/member/addAddress.vue';
import changePass from './components/member/changePass.vue';

var router = new VueRouter({
    routes : [
        { path : '/', redirect : '/home' }, /*路由重定向,使用 /+component 也能进入home但不高亮 */
        { path : '/home', component : homeContainer },
        { path : '/message', component : messageContainer },
        { path : '/cart', component : cartContainer },
        { path : '/member', component : memberContainer, name:'memberContainer'},

        { path : '/home/shopping', component : shopping},
        { path : '/home/news', component : newsList},
        { path : '/home/gallery', component : galleryList},
        { path : '/home/intro', component : introduce},
        { path : '/home/history', component : history},
        { path : '/home/poetry', component : poetry},
        { path : '/home/storeDetail/:storeId', component: storeDetail},
        
        { path : '/home/newsDetail', component : newsDetail},
        { path : '/home/galleryDetail/:type/:itemId', component : galleryDetail}, //路由一定要匹配，传几个值要确定
        { path : '/home/goodsList/:catesId', component : goodsList},
        { path : '/home/itemDetail/:gid', component : itemDetail},
        { path : '/member/register', component : register},
        { path : '/member/login', component : login},

        { path : '/member/addressList', component : addressList},
        { path : '/member/addAddress', component : addAddress},
        { path : '/member/changePass', component : changePass}

    ],
    scrollBehavior (to, from, savedPosition) {
        // 当切换到新路由时，想要页面滚到顶部，或者是保持原先的滚动位置，就像重新加载页面那样
        // 第三个参数 savedPosition 当且仅当 popstate 导航 (通过浏览器的 前进/后退 按钮触发) 时才可用
        // return 期望滚动到哪个的位置
        if (savedPosition) {
            return savedPosition
          } else {
            return { x: 0, y: 0 }
          }
          
      },
    linkActiveClass : 'mui-active', /*设置路由切换高亮显示的类 */
});

export default router;